package com.jijuxie.house.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jijuxie.house.domain.HouseImage;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface HouseImageMapper extends BaseMapper<HouseImage> {

    @Select("SELECT COALESCE(MAX(sort), 0) FROM house_image WHERE house_id = #{houseId}")
    Integer selectMaxSort(@Param("houseId") Long houseId);

    @Update("UPDATE house_image SET sort = sort - 1 "
            + "WHERE house_id = #{houseId} AND sort > #{deletedSort}")
    void reorderImages(@Param("houseId") Long houseId, @Param("deletedSort") Integer deletedSort);
}
